(function($){
//将form的值转换成json	
$.fn.serializeJson=function(){
var serializeObj={};
var array=this.serializeArray();
var str=this.serialize();
$(array).each(function(){
if(serializeObj[this.name]){
if($.isArray(serializeObj[this.name])){
serializeObj[this.name].push(this.value);
}else{
serializeObj[this.name]=[serializeObj[this.name],this.value];
}
}else{
serializeObj[this.name]=this.value;
}
});
return serializeObj;
};

$.extend({
	getRootPath:function(){
	var curWwwPath=window.document.location.href;
    var pathName=window.document.location.pathname;
    var pos=curWwwPath.indexOf(pathName);
    var localhostPaht=curWwwPath.substring(0,pos);
    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
    return(localhostPaht+projectName);
   }
});
//将form的值转换成json(不包含空字符串)
$.fn.serializeJsonNotNull=function(frm){
	var json = {};
    frm = frm || $('body');
    if (!frm) {
        return json;
    }
    var inputs = frm.find('input[type!=button][type!=reset][type!=submit][type!=image],select,textarea');
    if (!inputs) {
    	return json;
    }
    for (var index = 0; index < inputs.length; index++) {
    	var $input = inputs[index];
    	if($input.type === 'radio' && !$input.checked){
    		continue;
    	}
    	var input = $(inputs[index]);
    	var name = input.attr('name');
    	var value = input.val();
    	if (name != null && $.trim(name) != '' && value != null && $.trim(value) != ''&& $.trim(value) != '-1') {
    		json[name] = value;
    	}
    }
    return json;
}

})(jQuery);
